<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Information extends Model
{
   	protected $table = 'information';
	public $timestamps = false;

    /**
     * 默认数据
     * @param $typeid
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
	public function getdefaultnews($typeid)
    {
        if (!empty($typeid))
        {
            return Information::where('types','=',$typeid)->orderBy('publish_time','desc')->paginate(12);
        }
        else {
            return Information::orderBy('publish_time','desc')->paginate(12);
        }
    }

    /**
     * 获取热门
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getHot()
    {
        return Information::where('is_recommend','=',1)->limit(8)->get();
    }

    /**
     * 查询详情
     * @param $id
     * @return \Illuminate\Database\Eloquent\Collection|mixed|static[]
     */
    public function getDetials($id)
    {
        return Information::find($id);
    }

    /**
     * @param $id
     * @param $s
     */
    public function getOther($id,$type)
    {
        return Information::where('types','=',$type)->where('id','!=',$id)->get();
    }

    /**
     * 获取前台推荐
     */
    public function getSuggest($type)
    {
        return Information::where('is_recommend','=','1')->where('types','=',$type)->orderBy('publish_time','desc')->limit(10)->get();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getAtten()
    {
        return Information::where('attention','=',1)->limit(4)->get();
    }

    /**
     * 详情页调取最新资讯10条
     * @return mixed
     */
    public function getRand()
    {
        return DB::table('information')
            ->inRandomOrder()
            ->orderBy('publish_time','desc')
            ->take(10)
            ->get();
    }

    /**
     * 获取首页推荐的成功案例的内容
     * @return mixed
     */
    public function getRandNewsfour()
    {
        return DB::table('information')
            ->inRandomOrder()
            ->orderBy('publish_time','desc')
            ->where("types",'=',4)
            ->take(10)
            ->get();
    }
}
